package com.zsinfo.guoss.supplier.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.zsinfo.guoss.supplier.MyApplication;

/**
 * Created by Administrator on 2016/3/4.
 */
public class SharedPreferencesUtil {
    private static SharedPreferences sharedPreferences = MyApplication.instance.getSharedPreferences("userInfo", Context.MODE_PRIVATE);
    private static SharedPreferences.Editor editor = sharedPreferences.edit();

    public static float getFloatValue(String key) {
        return sharedPreferences.getFloat(key, 0.0f);
    }

    public static String getStringValue(String key) {
        return sharedPreferences.getString(key, "");
    }

    public static boolean getBooleanValue(String key) {
        return sharedPreferences.getBoolean(key, false);
    }

    public static float getIntValue(String key) {
        return sharedPreferences.getInt(key, 0);
    }

    public static void saveValue(String key, String value) {
        editor.putString(key, value).commit();
    }

    public static void saveValue(String key, float value) {
        editor.putFloat(key, value).commit();
    }

    public static void saveValue(String key, boolean value) {
        editor.putBoolean(key, value).commit();
    }

    public static void saveValue(String key, int value) {
        editor.putInt(key, value).commit();
    }


    /**
     * 是否第一次打开应用
     *
     * @return
     */
    public static boolean getFirstStart() {
        return sharedPreferences.getBoolean("FirstStart", true);
    }

    public static void setFirstStart() {
        editor.putBoolean("FirstStart", false).commit();
    }

    /**
     * 是否登录
     *
     * @return
     */
    public static boolean getIsLogin() {
        return sharedPreferences.getBoolean("IsLogin", false);
    }

    public static void setIsLogin(Boolean IsLogin) {
        editor.putBoolean("IsLogin", IsLogin).commit();
    }

    /**
     * token是否过期
     *
     * @return
     */
    public static String getToken() {
        return sharedPreferences.getString("Token", "");
    }

    public static void setToken(String token) {
        editor.putString("Token", token).commit();
    }

    /**
     * SecretKey
     *
     * @return
     */
    public static String getSecretKey() {
        return sharedPreferences.getString("SecretKey", "");
    }

    public static void setSecretKey(String SecretKey) {
        editor.putString("SecretKey", SecretKey).commit();
    }

    /**
     * websiteNode 站点编号
     *
     * @return
     */
    public static String getWebsiteNode() {
        return sharedPreferences.getString("websiteNode", "3301");
    }

    public static void setWebsiteNode(String websiteNode) {
        editor.putString("websiteNode", websiteNode).commit();
    }

    /**
     * websiteName 站点名称
     *
     * @return
     */
    public static String getwebsiteName() {
        return sharedPreferences.getString("websiteName", "杭州站");
    }

    public static void setWebsiteName(String websiteName) {
        editor.putString("websiteName", websiteName).commit();
    }

    /**
     * 加密之后的密码
     *
     * @return
     */
    public static String getPassword() {
        return sharedPreferences.getString("password", "");
    }

    public static void setPassword(String password) {
        editor.putString("password", password).commit();
    }

    /**
     * name 供应商名称
     *
     * @return
     */
    public static String getFirmName() {
        return sharedPreferences.getString("name", "");
    }

    public static void setfirmName(String firmName) {
        editor.putString("name", firmName).commit();
    }

    /**
     * id
     *
     * @return
     */
    public static String getID() {
        return sharedPreferences.getString("ID", "");
    }

    public static void setID(String ID) {
        editor.putString("ID", ID).commit();
    }

    /**
     * mobile 供应商登录电话
     *
     * @return
     */
    public static String getFirmMobile() {
        return sharedPreferences.getString("mobile", "");
    }

    public static void setFirmMobile(String firmId) {
        editor.putString("mobile", firmId).commit();
    }

    /**
     * 用户头像
     *
     * @return
     */
    public static String getFaceImg() {
        return sharedPreferences.getString("FaceImg", "");
    }

    public static void setFaceImg(String userGrade) {
        editor.putString("FaceImg", userGrade).commit();
    }

    /**
     * aLiName 支付宝名称
     *
     * @return
     */
    public static String getALiName() {
        return sharedPreferences.getString("aLiName", "");
    }

    public static void setALiName(String aLiName) {
        editor.putString("aLiName", aLiName).commit();
    }

    /**
     * aLiCount 支付宝账号
     *
     * @return
     */
    public static String getALiCount() {
        return sharedPreferences.getString("aLiCount", "");
    }

    public static void setALiCount(String aLiCount) {
        editor.putString("aLiCount", aLiCount).commit();
    }

    /**
     * ali_app_id
     *
     * @return
     */
    public static String getALiPayAppId() {
        return sharedPreferences.getString("alipay_app_id", "");
    }

    public static void setALiPayAppId(String alipay_app_id) {
        editor.putString("alipay_app_id", alipay_app_id).commit();
    }

    /**
     * alipay_rsa_private
     *
     * @return
     */
    public static String getALiPay_RSA_Private() {
        return sharedPreferences.getString("alipay_rsa_private", "");
    }

    public static void setALiPay_RSA_Private(String alipay_rsa_private) {
        editor.putString("alipay_rsa_private", alipay_rsa_private).commit();
    }

    /**
     * alipay_rsa_public
     *
     * @return
     */
    public static String getALiPay_RSA_Public() {
        return sharedPreferences.getString("alipay_rsa_public", "");
    }

    public static void setALiPay_RSA_Public(String alipay_rsa_public) {
        editor.putString("alipay_rsa_public", alipay_rsa_public).commit();
    }

    /**
     * 清除
     */
    public static void clearData() {
        editor.remove("FirstStart").commit();
        editor.remove("IsLogin").commit();
        editor.remove("Token").commit();
        editor.remove("ID").commit();
        editor.remove("SecretKey").commit();
        editor.remove("websiteNode").commit();
        editor.remove("websiteName").commit();
        editor.remove("name").commit();
        editor.remove("mobile").commit();
        editor.remove("password").commit();
        editor.remove("FaceImg").commit();
        editor.remove("aLiName").commit();
        editor.remove("aLiCount").commit();
        editor.remove("alipay_app_id").commit();
        editor.remove("alipay_rsa_private").commit();
        editor.remove("alipay_rsa_public").commit();
    }

}
